package com.atguigu.servlet;

import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;

import java.io.IOException;

@WebServlet("/servletB")
public class ServletB extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //  获得请求域存放数据
        String reqMsg = (String) req.getAttribute("request");
        System.out.println("request domain:"+reqMsg);
        // 获得会话域存放数据
        HttpSession session = req.getSession();
        String sessionMsg = (String) session.getAttribute("session");
        System.out.println("session domain:"+sessionMsg);

        // 获得应用域存放数据
        ServletContext ctx = getServletContext();
        String appMsg = (String) ctx.getAttribute("application");
        System.out.println("application domain:"+appMsg);
    }
}
